<include file="public@header" />
</head>

<body>
    <div class="wrap">
        <ul class="nav nav-tabs">
            <li class="active"><a>详情</a></li>
        </ul>
        <form method="post" class="form-horizontal js-ajax-form margin-top-20" action="{:url('doedit')}" enctype="multipart/form-data">


            <div class="form-group">
                <label for="js-smtpsecure" class="col-sm-2 control-label">
                    暂定总价
                </label>
                <div class="col-md-6 col-sm-10">
                    <input type="text" class="form-control" name="tempPrice" value="{$res['tempPrice']}">
                </div>
            </div>

            <div class="form-group">
                <label for="js-smtpsecure" class="col-sm-2 control-label">
                    组价描述
                </label>
                <div class="col-md-6 col-sm-10">
                    <textarea name="contentDesc" cols="10" rows="5"
                        class="form-control">{$res['contentDesc']}</textarea>
                </div>
            </div>

            <div class="form-group">
                <label for="js-smtpsecure" class="col-sm-2 control-label">
                    决算总价
                </label>
                <div class="col-md-6 col-sm-10">
                    <input type="text" class="form-control" name="deciPrice" value="{$res['deciPrice']}">
                </div>
            </div>

            <div class="form-group">
                <label for="js-smtpsecure" class="col-sm-2 control-label">
                    姓名
                </label>
                <div class="col-md-6 col-sm-10">
                    <select name="lid" id="nameSelect" class="form-control">
                        <option value="">请选择姓名</option>
                        <volist name="some" id="v">
                            <option value="{$v.id}" data-type="{$v['type']}" <eq name="v.id" value="$res.lid">selected
                                </eq>>{$v['name']}</option>
                        </volist>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label for="js-smtpsecure" class="col-sm-2 control-label">
                    班组
                </label>
                <div class="col-md-6 col-sm-10">
                    <input type="text" id="teamDisplay" class="form-control" readonly>
                    <!-- <select name="tid" id="teamSelect" class="form-control">
                    <option value="">请选择班组</option>
                    <volist name="some" id="v">
                        <option value="{$v.id}" <eq name="v.id" value="$res.tid">selected</eq>>{$v['type']}</option>
                    </volist>
                </select> -->
                </div>
            </div>


            <div class="form-group">
                <label for="js-smtpsecure" class="col-sm-2 control-label">
                    决算明细
                </label>
                <div class="col-md-6 col-sm-10">
                    <input type="file" name="img[]" class="form-control" id="imgUpload" multiple accept="image/*" />
                    <div id="imgPreviewContainer" class="image-preview-container" style="margin-top: 10px; display: flex; flex-wrap: wrap;"></div>
                </div>
            </div>

            <div class="form-group">
                <label for="js-smtpsecure" class="col-sm-2 control-label">
                    合同
                </label>
                <div class="col-md-6 col-sm-10">
                    <input type="file" name="contract[]" class="form-control" id="contractUpload" multiple accept="image/*" />
                    <div id="contractPreviewContainer" class="image-preview-container" style="margin-top: 10px; display: flex; flex-wrap: wrap;"></div>
                </div>
            </div>


            <input type="hidden" name="id" value="{$res['id']}">

            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="submit" class="btn btn-primary js-ajax-submit">{:lang('SAVE')}</button>
                    <a class="btn btn-default" href="javascript:history.back(-1);">{:lang('BACK')}</a>
                </div>
            </div>
        </form>
    </div>
    <script src="__STATIC__/js/admin.js"></script>
    <script src="__STATIC__/js/image-uploader.js"></script>
    <script>
        // 页面加载时初始化班组
        function initializeTeamDisplay() {
            const nameSelect = document.getElementById('nameSelect');
            const selectedOption = nameSelect.options[nameSelect.selectedIndex];
            if (selectedOption) {
                const typeValue = selectedOption.getAttribute('data-type');
                const teamDisplay = document.getElementById('teamDisplay');
                teamDisplay.value = typeValue || ''; // 设置班组输入框的值
            }
        }

        // 姓名选择框联动班组
        document.getElementById('nameSelect').addEventListener('change', function () {
            const selectedOption = this.options[this.selectedIndex];
            if (selectedOption) {
                const typeValue = selectedOption.getAttribute('data-type');
                const teamDisplay = document.getElementById('teamDisplay');
                teamDisplay.value = typeValue || ''; // 设置班组输入框的值
            }
        });

        // 页面加载完成后初始化所有功能
        document.addEventListener('DOMContentLoaded', function() {
            // 初始化班组显示
            initializeTeamDisplay();
            
            // 初始化图片上传组件
            // 决算明细图片上传
            const imgUploader = new ImageUploader({
                inputId: 'imgUpload',
                previewContainerId: 'imgPreviewContainer',
                fieldName: 'img',
                existingImages: [
                    <if condition="$res['img'] !== false">
                        <volist name="res['img']" id="v" key="k">
                            "{$v}",
                        </volist>
                    </if>
                ],
                useDataTransfer: true
            });
            
            // 合同图片上传
            const contractUploader = new ImageUploader({
                inputId: 'contractUpload',
                previewContainerId: 'contractPreviewContainer',
                fieldName: 'contract',
                existingImages: [
                    <if condition="$res['contract'] !== false">
                        <volist name="res['contract']" id="v" key="k">
                            "{$v}",
                        </volist>
                    </if>
                ],
                useDataTransfer: true
            });
        });
    </script>
</body>

</html>